package jjn.daily;

import java.util.Scanner;

/**
 * @author Jiang Jining
 * @since 2023-07-20 23:04
 */
public class LeetCode53 {
    public int maxSubArray(int[] nums) {
        int[] dp = new int[nums.length + 1];
        dp[0] = nums[0];
        int max = nums[0];
        for (int i = 1; i < nums.length; i++) {
            if (dp[i - 1] > 0) {
                dp[i] = dp[i - 1] + nums[i];
            } else {
                dp[i] = nums[i];
            }
            max = Math.max(dp[i], max);
        }
        return max;
    }
    
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int count = scanner.nextInt();
        int[] nums = new int[count];
        for (int i = 0; i < count; i++) {
            nums[i] = scanner.nextInt();
        }
        int maxSubArray = new LeetCode53().maxSubArray(nums);
        System.out.println("maxSubArray = " + maxSubArray);
    }
}
